home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Games / Pararena 1.3 / source / Parts ƒ / Unlock.p < prev    next >
Encoding:
Text File  |  1991-05-15  |  11.5 KB  |  506 lines  |  [TEXT/PJMM]

  1. unit Unlock;
  2.  
  3. interface
  4.     uses
  5.         Sound, Globals;
  6.  
  7.     function ShowAboutDialog: Boolean;
  8.     procedure DoUnlock;
  9.     procedure GetName (var theName: Str255);
  10.     procedure DoGreatestScore;
  11.     procedure DoDeltaScore;
  12.     procedure ShowHiScores;
  13.  
  14. implementation
  15.  
  16. {=============================}
  17.  
  18.     function ShowAboutDialog;
  19.         const
  20.             okayButton = 1;
  21.             moreButton = 2;
  22.  
  23.         var
  24.             theDlgPtr: DialogPtr;
  25.             tempRect: Rect;
  26.             itemT, itemHit: Integer;
  27.             itemH: Handle;
  28.             exitDialog: Boolean;
  29.  
  30. {----------------}
  31.  
  32.         procedure DrawDefault;
  33.         begin
  34.             GetDItem(theDlgPtr, okayButton, itemT, itemH, tempRect);
  35.             PenSize(3, 3);
  36.             InsetRect(tempRect, -4, -4);
  37.             FrameRoundRect(tempRect, 16, 16);
  38.             PenSize(1, 1);
  39.         end;
  40.  
  41. {----------------}
  42.  
  43.     begin
  44.         ShowAboutDialog := FALSE;
  45.         CenterDialog(aboutDialID);
  46.         theDlgPtr := GetNewDialog(aboutDialID, nil, Pointer(-1));
  47.         ShowWindow(theDlgPtr);
  48.         SetPort(GrafPtr(theDlgPtr));
  49.  
  50.         exitDialog := FALSE;
  51.         DrawDefault;
  52.  
  53.         repeat
  54.             ModalDialog(nil, itemHit);
  55.  
  56.             if (ItemHit = okayButton) then
  57.                 exitDialog := TRUE;
  58.  
  59.             if (ItemHit = moreButton) then
  60.                 begin
  61.                     exitDialog := TRUE;
  62.                     ShowAboutDialog := TRUE;
  63.                 end;
  64.  
  65.         until exitDialog;
  66.  
  67.         DisposDialog(theDlgPtr);
  68.     end;
  69.  
  70. {=============================}
  71.  
  72.     procedure DoUnlock;
  73.         const
  74.             okayButton = 1;
  75.             unlockButton = 2;
  76.             passWordEdit = 3;
  77.             passNumEdit = 4;
  78.             userItem = 20;
  79.             userItem2 = 21;
  80.  
  81.         var
  82.             theDlgPtr: DialogPtr;
  83.             tempRect: Rect;
  84.             itemT, itemHit, i, tempInt: Integer;
  85.             itemH: Handle;
  86.             tempChar: Char;
  87.             theKey, theirKey: LongInt;
  88.             theirPass, thePass, tempStr: Str255;
  89.             exitMe: Boolean;
  90.  
  91. {----------------}
  92.  
  93.         procedure DrawDefaultAndFrame;
  94.         begin
  95.             ForeColor(redColor);
  96.             GetDItem(theDlgPtr, userItem, itemT, itemH, tempRect);
  97.             FrameRect(tempRect);
  98.             GetDItem(theDlgPtr, userItem2, itemT, itemH, tempRect);
  99.             FrameRect(tempRect);
  100.             ForeColor(blackColor);
  101.             GetDItem(theDlgPtr, okayButton, itemT, itemH, tempRect);
  102.             PenSize(3, 3);
  103.             InsetRect(tempRect, -4, -4);
  104.             FrameRoundRect(tempRect, 16, 16);
  105.             PenNormal;
  106.         end;
  107.  
  108. {----------------}
  109.  
  110.         procedure WordToKey;
  111.         begin
  112.             tempChar := COPY(theirPass, 1, 1);
  113.             theKey := ORD(tempChar);
  114.             theKey := theKey * 1000;
  115.             tempChar := COPY(theirPass, 2, 1);
  116.             theKey := theKey + ORD(tempChar) * 100;
  117.             tempChar := COPY(theirPass, 3, 1);
  118.             theKey := theKey + ORD(tempChar) * 100;
  119.             tempChar := COPY(theirPass, 4, 1);
  120.             theKey := theKey + ORD(tempChar) * 10;
  121.             tempChar := COPY(theirPass, 5, 1);
  122.             theKey := theKey + ORD(tempChar) * 10;
  123.             tempChar := COPY(theirPass, 6, 1);
  124.             theKey := theKey + ORD(tempChar) * 10;
  125.             tempChar := COPY(theirPass, 7, 1);
  126.             theKey := theKey + ORD(tempChar);
  127.             tempChar := COPY(theirPass, 8, 1);
  128.             theKey := theKey + ORD(tempChar);
  129.         end;
  130.  
  131. {----------------}
  132.  
  133.         procedure UnlockTheGame;
  134.             var
  135.                 i: Integer;
  136.         begin
  137.             timeToLock := 30;
  138.             tempChar := CHR(25);
  139.             tempStr := CONCAT('B', tempChar);
  140.             prefsStr := CONCAT(tempStr, COPY(prefsStr, 3, 7));
  141.             tempStr := '';
  142.             for i := 1 to 8 do
  143.                 begin
  144.                     tempChar := COPY(theirPass, i, 1);
  145.                     tempInt := (ORD(tempChar) div 10) + 65;
  146.                     tempChar := CHR(tempInt);
  147.                     tempStr := CONCAT(tempStr, tempChar);
  148.                     tempChar := COPY(theirPass, i, 1);
  149.                     tempInt := (ORD(tempChar) mod 10) + 75;
  150.                     tempChar := CHR(tempInt);
  151.                     tempStr := CONCAT(tempStr, tempChar);
  152.                 end;
  153.             prefsStr := CONCAT(prefsStr, tempStr);
  154.  
  155.             GetDItem(theDlgPtr, userItem, itemT, itemH, tempRect);
  156.             InvertRect(tempRect);
  157.  
  158.             if (locked) then
  159.                 DeleteMenu(133);
  160.             locked := FALSE;
  161.  
  162.             EnableItem(GetMenu(mWhichGame), iFourOfNine);
  163.             EnableItem(GetMenu(mWhichGame), iFirstTo13);
  164.             EnableItem(GetMenu(mOpponents), iMara);
  165.             EnableItem(GetMenu(mOpponents), iClaire);
  166.             EnableItem(GetMenu(mOptions), iPhysics);
  167.             DrawMenuBar;
  168.         end;
  169.  
  170. {----------------}
  171.  
  172.     begin
  173.         CenterDialog(unlockDialID);
  174.         theDlgPtr := GetNewDialog(unlockDialID, nil, Pointer(-1));
  175.         ShowWindow(theDlgPtr);
  176.         SetPort(theDlgPtr);
  177.  
  178.         GetDItem(theDlgPtr, passWordEdit, itemT, itemH, tempRect);
  179.         SetIText(itemH, 'password');
  180.         GetDItem(theDlgPtr, passNumEdit, itemT, itemH, tempRect);
  181.         SetIText(itemH, '87654321');
  182.         SelIText(theDlgPtr, passWordEdit, 0, 15);
  183.  
  184.         DrawDefaultAndFrame;
  185.         exitMe := FALSE;
  186.  
  187.         repeat
  188.             ModalDialog(nil, itemHit);
  189.  
  190.             if (itemHit = okayButton) then
  191.                 exitMe := TRUE;
  192.  
  193.             if (ItemHit = unlockButton) then
  194.                 begin
  195.                     GetDItem(theDlgPtr, passWordEdit, itemT, itemH, tempRect);
  196.                     GetIText(itemH, theirPass);
  197.                     theirPass := CONCAT(theirPass, '        ');
  198.                     theirPass := COPY(theirPass, 1, 8);
  199.                     UprString(theirPass, TRUE);
  200.  
  201.                     WordToKey;
  202.  
  203.                     thePass := '';
  204.                     for i := 0 to 7 do
  205.                         begin
  206.                             tempChar := COPY(prefsStr, (i * 2) + 10, 1);
  207.                             tempInt := (ORD(tempChar) - 65) * 10;
  208.                             tempChar := COPY(prefsStr, (i * 2) + 11, 1);
  209.                             tempInt := tempInt + (ORD(tempChar) - 75);
  210.                             thePass := CONCAT(thePass, CHR(tempInt));
  211.                         end;
  212.  
  213.                     GetDItem(theDlgPtr, passNumEdit, itemT, itemH, tempRect);
  214.                     GetIText(itemH, tempStr);
  215.                     StringToNum(tempStr, theirKey);
  216.  
  217.                     if ((theirKey = theKey) or (thePass = theirPass)) then
  218.                         UnlockTheGame;
  219.                 end;
  220.  
  221.         until exitMe;
  222.  
  223.         DisposDialog(theDlgPtr);
  224.     end;
  225.  
  226. {=============================}
  227.  
  228.     procedure GetName;
  229.         const
  230.             okayButton = 1;
  231.             nameEdit = 2;
  232.  
  233.         var
  234.             theDlgPtr: DialogPtr;
  235.             tempRect: Rect;
  236.             itemT, itemHit: Integer;
  237.             itemH: Handle;
  238.             exitMe: Boolean;
  239.  
  240. {----------------}
  241.  
  242.         procedure DrawDefault;
  243.         begin
  244.             ForeColor(redColor);
  245.             GetDItem(theDlgPtr, okayButton, itemT, itemH, tempRect);
  246.             PenSize(3, 3);
  247.             InsetRect(tempRect, -4, -4);
  248.             FrameRoundRect(tempRect, 16, 16);
  249.             ForeColor(blackColor);
  250.             PenNormal;
  251.         end;
  252.  
  253. {----------------}
  254.  
  255.     begin
  256.         CenterDialog(hiscoreDialID);
  257.         theDlgPtr := GetNewDialog(hiscoreDialID, nil, Pointer(-1));
  258.         ShowWindow(theDlgPtr);
  259.         SetPort(theDlgPtr);
  260.  
  261.         GetDItem(theDlgPtr, nameEdit, itemT, itemH, tempRect);
  262.         SetIText(itemH, '15 characters');
  263.         SelIText(theDlgPtr, nameEdit, 0, 25);
  264.  
  265.         DrawDefault;
  266.         exitMe := FALSE;
  267.  
  268.         repeat
  269.             ModalDialog(nil, itemHit);
  270.  
  271.             if (itemHit = okayButton) then
  272.                 begin
  273.                     GetDItem(theDlgPtr, nameEdit, itemT, itemH, tempRect);
  274.                     GetIText(itemH, theName);
  275.                     if (LENGTH(theName) > 15) then
  276.                         begin
  277.                             SysBeep(1);
  278.                             theName := COPY(theName, 1, 15);
  279.                             GetIText(itemH, theName);
  280.                             SelIText(theDlgPtr, nameEdit, 0, 25);
  281.                         end
  282.                     else
  283.                         begin
  284.                             theName := CONCAT(theName, '               ');
  285.                             theName := COPY(theName, 1, 15);
  286.                             exitMe := TRUE;
  287.                         end;
  288.                 end;
  289.  
  290.         until exitMe;
  291.  
  292.         DisposDialog(theDlgPtr);
  293.     end;
  294.  
  295. {=============================}
  296.  
  297.     procedure DoGreatestScore;
  298.         var
  299.             theName: Str255;
  300.             winner, loser, index, place: Integer;
  301.     begin
  302.         if ((earthPoints > taygetePoints) or ((earthPoints = taygetePoints) and (earthFouls < taygeteFouls))) then
  303.             begin
  304.                 theName := playerName;
  305.                 winner := earthPoints;
  306.                 loser := taygetePoints;
  307.             end
  308.         else
  309.             begin
  310.                 case whichOpponent of
  311.                     mara: 
  312.                         theName := 'Mad Mara       ';
  313.                     otto: 
  314.                         theName := 'Heavy Otto     ';
  315.                     george: 
  316.                         theName := 'Simple George  ';
  317.                     claire: 
  318.                         theName := 'Clever Claire  ';
  319.                     otherwise
  320.                         begin
  321.                         end;
  322.                 end;
  323.                 winner := taygetePoints;
  324.                 loser := earthPoints;
  325.             end;
  326.  
  327.         with hiScores do
  328.             begin
  329.                 place := 11;
  330.                 for index := 10 downto 0 do
  331.                     if (winner > greatScores[index, 0]) then
  332.                         place := index;
  333.                 for index := 11 downto place + 1 do
  334.                     begin
  335.                         greatScores[index, 0] := greatScores[index - 1, 0];
  336.                         greatScores[index, 1] := greatScores[index - 1, 1];
  337.                         greatNames[index] := greatNames[index - 1];
  338.                     end;
  339.                 greatScores[place, 0] := winner;
  340.                 greatScores[place, 1] := loser;
  341.                 greatNames[place] := theName;
  342.  
  343.                 smallestGreatest := greatScores[11, 0];
  344.             end;
  345.  
  346.         scoresChanged := TRUE;
  347.  
  348.     end;
  349.  
  350. {=============================}
  351.  
  352.     procedure DoDeltaScore;
  353.         var
  354.             theName: Str255;
  355.             winner, loser, index, place, thisDiff: Integer;
  356.     begin
  357.         if (earthPoints > taygetePoints) then
  358.             begin
  359.                 theName := playerName;
  360.                 winner := earthPoints;
  361.                 loser := taygetePoints;
  362.             end
  363.         else
  364.             begin
  365.                 case whichOpponent of
  366.                     mara: 
  367.                         theName := 'Mad Mara       ';
  368.                     otto: 
  369.                         theName := 'Heavy Otto     ';
  370.                     george: 
  371.                         theName := 'Simple George  ';
  372.                     claire: 
  373.                         theName := 'Clever Claire  ';
  374.                     otherwise
  375.                         begin
  376.                         end;
  377.                 end;
  378.                 winner := taygetePoints;
  379.                 loser := earthPoints;
  380.             end;
  381.  
  382.         thisDiff := winner - loser;
  383.  
  384.         with hiScores do
  385.             begin
  386.                 place := 11;
  387.                 for index := 10 downto 0 do
  388.                     if (thisDiff > (deltaScores[index, 0] - deltaScores[index, 1])) then
  389.                         place := index;
  390.                 for index := 11 downto place + 1 do
  391.                     begin
  392.                         deltaScores[index, 0] := deltaScores[index - 1, 0];
  393.                         deltaScores[index, 1] := deltaScores[index - 1, 1];
  394.                         deltaNames[index] := deltaNames[index - 1];
  395.                     end;
  396.                 deltaScores[place, 0] := winner;
  397.                 deltaScores[place, 1] := loser;
  398.                 deltaNames[place] := theName;
  399.  
  400.                 smallestDelta := deltaScores[11, 0] - deltaScores[11, 1];
  401.             end;
  402.  
  403.         scoresChanged := TRUE;
  404.     end;
  405.  
  406. {=============================}
  407.  
  408.     procedure ShowHiScores;
  409.         var
  410.             index: Integer;
  411.             dummyLong: LongInt;
  412.             scoreStr, first, second: Str255;
  413.             mousePt: Point;
  414.             thePict: PicHandle;
  415.             tempRect: Rect;
  416.             clickedIt: Boolean;
  417.     begin
  418.         CopyBits(mainWndo^.portBits, offLoadMap, screenArea, screenArea, srcCopy, wholeRgn);
  419.         SetPort(mainWndo);
  420.         thePict := GetPicture(2002);
  421.         if (thePict <> nil) then
  422.             begin
  423.                 HLock(Handle(thePict));
  424.                 tempRect := thePict^^.picFrame;
  425.                 OffsetRect(tempRect, 8, 44);
  426.                 DrawPicture(thePict, tempRect);
  427.                 HUnlock(Handle(thePict));
  428.                 ReleaseResource(Handle(thePict));
  429.             end
  430.         else
  431.             Exit(ShowHiScores);
  432.  
  433.         PenNormal;
  434.         TextMode(srcXOr);
  435.         TextFont(Monaco);
  436.         TextSize(9);
  437.         with hiScores do
  438.             for index := 0 to 11 do
  439.                 begin
  440.                     MoveTo(68, 101 + index * 11 + (index + 2) div 2);
  441.                     DrawString(greatNames[index]);
  442.                     NumToString(greatScores[index, 0], first);
  443.                     MoveTo(180, 101 + index * 11 + (index + 2) div 2);
  444.                     DrawString(first);
  445.                     MoveTo(200, 101 + index * 11 + (index + 2) div 2);
  446.                     DrawString('to');
  447.                     NumToString(greatScores[index, 1], second);
  448.                     MoveTo(220, 101 + index * 11 + (index + 2) div 2);
  449.                     DrawString(second);
  450.  
  451.                     MoveTo(306, 101 + index * 11 + (index + 2) div 2);
  452.                     DrawString(deltaNames[index]);
  453.                     NumToString(deltaScores[index, 0], first);
  454.                     MoveTo(418, 101 + index * 11 + (index + 2) div 2);
  455.                     DrawString(first);
  456.                     MoveTo(438, 101 + index * 11 + (index + 2) div 2);
  457.                     DrawString('to');
  458.                     NumToString(deltaScores[index, 1], second);
  459.                     MoveTo(458, 101 + index * 11 + (index + 2) div 2);
  460.                     DrawString(second);
  461.                 end;
  462.  
  463.         PenNormal;
  464.         clickedIt := FALSE;
  465.         repeat
  466.         until (not Button);
  467.         repeat
  468.             ForeColor(yellowColor);
  469.             FrameRect(tempRect);
  470.             for index := 1 to 10 do
  471.                 begin
  472.                     Delay(1, dummyLong);
  473.                     clickedIt := Button;
  474.                 end;
  475.  
  476.             ForeColor(blackColor);
  477.             FrameRect(tempRect);
  478.             for index := 1 to 10 do
  479.                 begin
  480.                     Delay(1, dummyLong);
  481.                     clickedIt := Button;
  482.                 end;
  483.         until clickedIt;
  484.         GetMouse(mousePt);
  485.  
  486.         if ((mousePt.h = 0) and (mousePt.v = 0)) then
  487.             begin
  488.                 with hiScores do
  489.                     for index := 0 to 11 do
  490.                         begin
  491.                             greatNames[index] := '===============';
  492.                             deltaNames[index] := '===============';
  493.                             greatScores[index, 0] := 0;
  494.                             greatScores[index, 1] := 0;
  495.                             deltaScores[index, 0] := 0;
  496.                             deltaScores[index, 1] := 0;
  497.                         end;
  498.                 scoresChanged := TRUE;
  499.             end;
  500.         PenNormal;
  501.         CopyBits(offLoadMap, mainWndo^.portBits, screenArea, screenArea, srcCopy, nil);
  502.     end;
  503.  
  504. {=============================}
  505.  
  506. end.                                    {End of unit}